package com.itheima.controller.v1;

import com.itheima.common.R;
import com.itheima.controller.v1.api.CourseControllerApi;
import com.itheima.dto.CourseDto;
import com.itheima.pojo.TbCourse;
import com.itheima.service.TbCourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/course")
@Slf4j
@CrossOrigin
public class CourseController implements CourseControllerApi {
    @Autowired
    private TbCourseService tbCourseService;

    //课程分页条件查询接口
    @Override
    @GetMapping("/list")
    public R listCourse(CourseDto courseDto) {
        R r = tbCourseService.listCourse(courseDto);
        return r;
    }

    //添加课程接口
    @Override
    @PostMapping
    public R addCourse(@RequestBody TbCourse tbCourse) {
        R r = tbCourseService.addCourse(tbCourse);
        return r;
    }

    //修改课程--课程回显接口
    @Override
    @GetMapping("/{id}")
    public R getCourseById(@PathVariable Long id) {
        R r = tbCourseService.getCourseById(id);
        return r;
    }


    //修改课程--确认修改接口
    @Override
    @PutMapping
    public R modifyCourse(@RequestBody TbCourse tbCourse) {
        R r = tbCourseService.modifyCourse(tbCourse);
        return r;
    }

    //删除课程接口
    @Override
    @DeleteMapping("/{id}")
    public R removeCourse(@PathVariable Long id) {
        R r = tbCourseService.removeCourse(id);
        return r;
    }

    //批量删除课程接口
    @Override
    @GetMapping
    public R removeCoueses(Long[] ids) {
        R r = tbCourseService.removeCoueses(ids);
        return r;
    }

    //合同管理的高级搜索的购买课程列表选择
    @Override
    @GetMapping("/listSelect")
    public R listSelect() {
        R r = tbCourseService.listSelect();
        return r;
    }


}
